package com.neuronbit.businessflow.intellij.psi;

import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReference;
import com.intellij.refactoring.changeSignature.CallReferenceUsageInfo;
import com.intellij.refactoring.changeSignature.ChangeInfo;
import com.intellij.refactoring.changeSignature.PsiCallReference;
import com.intellij.usageView.UsageInfo;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

/**
 * 只有下列情况，该类才会被调用
 * boolean needToChangeCalls =
 * !myChangeInfo.isGenerateDelegate() && (myChangeInfo.isNameChanged() ||
 * myChangeInfo.isParameterSetOrOrderChanged() ||
 * myChangeInfo.isExceptionSetOrOrderChanged() ||
 * myChangeInfo.isVisibilityChanged());
 * 如果是myChangeInfo.isParameterTypesChanged()，则只能通过MethodReferencesSearch来提供 reference
 */
public class ChangeSignatureUsageProvider implements com.intellij.refactoring.changeSignature.ChangeSignatureUsageProvider {

    @Override
    public @Nullable UsageInfo createUsageInfo(@NotNull ChangeInfo changeInfo,
                                               @NotNull PsiReference reference,
                                               @NotNull PsiElement method,
                                               boolean modifyArgs,
                                               boolean modifyExceptions) {
        if (reference instanceof PsiCallReference) {
            return new CallReferenceUsageInfo((PsiCallReference) reference);
        } else {
            return null;
        }
    }

    @Override
    public @Nullable UsageInfo createOverrideUsageInfo(@NotNull ChangeInfo changeInfo,
                                                       @NotNull PsiElement overrider,
                                                       @NotNull PsiElement baseMethod,
                                                       boolean isOriginalOverrider,
                                                       boolean modifyArgs,
                                                       boolean modifyExceptions,
                                                       List<? super UsageInfo> result) {
        return null;
    }
}
